package cn.cgg;

import io.netty.util.CharsetUtil;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class PublicProducer {
    //同步发送
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("hello-world");
        //设置 name  server地址
        producer.setNamesrvAddr(Constants.NAME_SERVER_URL);
        //设置队列数量  默认为4
        producer.setDefaultTopicQueueNums(8);
        //启动
        producer.start();
        for (int i = 0 ; i < 16 ; i++) {
            Message message = new Message();
            message.setTopic("log-topic");
            message.setTags("info_tag");
            //添加内容
            message.setBody((i+"我是大脑壳").getBytes(CharsetUtil.UTF_8));
            //执行发送
            SendResult result = producer.send(message);
            System.out.println(result);
        }
        //关闭生产者
        producer.shutdown();
    }
}
